//
//  UIBarButtonItem+Extension.m
//  XLWeiBo-1.0
//
//  Created by lanou3g on 15/10/24.
//  Copyright © 2015年 崔丰帅. All rights reserved.
//

#import "UIBarButtonItem+Extension.h"

@implementation UIBarButtonItem (Extension)
+ (UIBarButtonItem *)itemWithTarget:(id)target action:(SEL)action image:(NSString *)image highImage:(NSString *)highImage {
    // 创建一个按钮
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    // 添加点击时间
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    // 设置按钮的图片
    [btn setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:highImage] forState:UIControlStateHighlighted];
    
    // 设置图片大小
    CGFloat sizeW = 35;
    CGFloat sizeH = sizeW;
    btn.size = CGSizeMake(sizeW, sizeH);
    btn.layer.cornerRadius = sizeW * 0.5;
    btn.layer.borderWidth = 3;
    btn.layer.borderColor = [UIColor purpleColor].CGColor;
    btn.clipsToBounds = YES;
    
    // 返回 barButtonItem
    return [[UIBarButtonItem alloc] initWithCustomView:btn];
}

+ (UIBarButtonItem *)itemWithTarget:(id)target action:(SEL)action title:(NSString *)title {
    UIButton *sendBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    //设置按钮文字
    NSString *btnStr = title;
    // 添加按钮文字属性
      // 可用属性
    NSMutableAttributedString *btnAttStrNormal = [[NSMutableAttributedString alloc] initWithString:btnStr];
    [btnAttStrNormal addAttributes:@{NSForegroundColorAttributeName:[UIColor orangeColor], NSFontAttributeName:[UIFont systemFontOfSize:15]} range:NSMakeRange(0, 2)];
    [sendBtn setAttributedTitle:btnAttStrNormal forState:UIControlStateNormal];
      // 不可用属性
    NSMutableAttributedString *btnAttStrDisabled = [[NSMutableAttributedString alloc] initWithString:btnStr];
    [btnAttStrDisabled addAttributes:@{NSForegroundColorAttributeName:[UIColor grayColor], NSFontAttributeName:[UIFont systemFontOfSize:15]} range:NSMakeRange(0, 2)];
    [sendBtn setAttributedTitle:btnAttStrDisabled forState:UIControlStateDisabled];
    
    // 设置按钮尺寸
    sendBtn.size = CGSizeMake(30, 30);
    // 添加点击时间
    [sendBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];

    return [[UIBarButtonItem alloc] initWithCustomView:sendBtn];
}

@end
